//
//  UserDefaults.m
//  LabanBrowser
//
//  Created by Xh2 on 3/29/13.
//  Copyright (c) 2013 VNG. All rights reserved.
//

#import "UserDefaults.h"

@implementation UserDefaults
@dynamic webDisplayMode;
@dynamic suggestion;
@dynamic keepScreenOn;

@dynamic howOftenToCheckForUpdate;
@dynamic webFontSize;
@dynamic webZoomScale;
@dynamic webUserAgent;
@dynamic language;
@dynamic theme;
@dynamic fullscreenWhenInLandscape;
@dynamic incognitoMode;
@dynamic showPinchZoomButton;
@dynamic acceptCookies;
@dynamic enableLocation;
@dynamic rememberFormData;
@dynamic rememberPasswords;
@dynamic showSecurityWarning;
@dynamic orientation;
-(id)init{
    self=[super init];
    if(self){
        
    }
    return self;
}

#pragma mark - BROWSER SETTINGS
-(NSNumber *)suggestion{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"suggestion"]==nil){
        [self setSuggestion:[NSNumber numberWithBool:YES]];
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"suggestion"];
}

-(void)setSuggestion:(NSNumber *)suggestion{
    [[NSUserDefaults standardUserDefaults]setObject:suggestion forKey:@"suggestion"];
}

-(NSNumber *)keepScreenOn{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"keepScreenOn"]==nil){
        [self setKeepScreenOn:[NSNumber numberWithBool:YES]];
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"keepScreenOn"];
}

-(void)setKeepScreenOn:(NSNumber *)keepScreenOn{
    [[NSUserDefaults standardUserDefaults]setObject:keepScreenOn forKey:@"keepScreenOn"];
}

-(NSNumber *)orientation{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"orientation"]==nil){
        [self setOrientation:[NSNumber numberWithInt:0]];
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"orientation"];
}

-(void)setOrientation:(NSNumber *)orientation{
    [[NSUserDefaults standardUserDefaults]setObject:orientation forKey:@"orientation"];
}






-(NSNumber *)showPinchZoomButton{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"showPinchZoomButton"]==nil){
        [self setShowPinchZoomButton:[NSNumber numberWithBool:NO]];
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"showPinchZoomButton"];
}
-(void)setShowPinchZoomButton:(NSNumber *)showPinchZoomButton{
    [[NSUserDefaults standardUserDefaults]setObject:showPinchZoomButton forKey:@"showPinchZoomButton"];
}

-(NSNumber *)fullscreenWhenInLandscape{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"fullscreenWhenInLandscape"]==nil){
        [self setFullscreenWhenInLandscape:[NSNumber numberWithBool:YES]];
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"fullscreenWhenInLandscape"];
}
-(void)setFullscreenWhenInLandscape:(NSNumber *)fullscreenWhenInLandscape{
    [[NSUserDefaults standardUserDefaults]setObject:fullscreenWhenInLandscape forKey:@"fullscreenWhenInLandscape"];

}

-(NSNumber *)incognitoMode{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"incognitoMode"]==nil){
        [self setIncognitoMode:[NSNumber numberWithBool:NO]];
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"incognitoMode"];
}
-(void)setIncognitoMode:(NSNumber *)incognitoMode{
    [[NSUserDefaults standardUserDefaults]setObject:incognitoMode forKey:@"incognitoMode"];
}


-(NSNumber *)howOftenToCheckForUpdate{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"checkForUpdate"]==nil){
        [self setHowOftenToCheckForUpdate:[NSNumber numberWithInt:0]];
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"checkForUpdate"];
}
-(void)setHowOftenToCheckForUpdate:(NSNumber *)howOftenToCheckForUpdate{
    [[NSUserDefaults standardUserDefaults]setObject:howOftenToCheckForUpdate forKey:@"checkForUpdate"];
    
}

#pragma mark - PAGE CONTENT SETTINGS

-(NSNumber *)webDisplayMode{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"WebDisplayMode"]==nil){
        [self setWebDisplayMode:[NSNumber numberWithInt:0]];
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"WebDisplayMode"];
}
-(void)setWebDisplayMode:(NSNumber *)webDisplayMode{
    [[NSUserDefaults standardUserDefaults]setObject:webDisplayMode forKey:@"WebDisplayMode"];
}




-(NSNumber *)webFontSize{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"fontSize"]==nil){
        [self setWebFontSize:[NSNumber numberWithInt:2]];
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"fontSize"];
}

-(void)setWebFontSize:(NSNumber *)webFontSize{
    [[NSUserDefaults standardUserDefaults]setObject:webFontSize forKey:@"fontSize"];

}

-(NSNumber *)webZoomScale{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"defaultZoom"]==nil){
        [self setWebZoomScale:[NSNumber numberWithInt:1]];
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"defaultZoom"];
}

-(void)setWebZoomScale:(NSNumber *)webZoomScale{
    [[NSUserDefaults standardUserDefaults]setObject:webZoomScale forKey:@"defaultZoom"];
}

-(NSNumber *)webUserAgent{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"userAgent"]==nil){
        if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
            [self setWebUserAgent:[NSNumber numberWithInt:2]];
        }else{
            [self setWebUserAgent:[NSNumber numberWithInt:6]];
        }
        
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"userAgent"];

}
-(void)setWebUserAgent:(NSNumber *)webUserAgent{
    [[NSUserDefaults standardUserDefaults]setObject:webUserAgent forKey:@"userAgent"];

}
-(NSNumber *)language{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"language"]==nil){
        [self setLanguage:[NSNumber numberWithInt:0]];
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"language"];
}
-(void)setLanguage:(NSNumber *)language{
    [[NSUserDefaults standardUserDefaults]setObject:language forKey:@"language"];

}

-(NSString *)getLanguageString{
    int languageIndex = [[self language]intValue];
    NSString* stringResult =@"";
    switch (languageIndex) {
        case 0:
            stringResult = @"vi";
            break;
            
        case 1:
            stringResult = @"en";
            break;
    }
    return stringResult;
}

-(NSNumber *)theme{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"theme"]==nil){
        [self setTheme:[NSNumber numberWithInt:0]];
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"theme"];
}
-(void)setTheme:(NSNumber *)theme{
    [[NSUserDefaults standardUserDefaults]setObject:theme forKey:@"theme"];

}

#pragma mark - PRIVACY SETTINGS
-(NSNumber *)showSecurityWarning{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"showSecurityWarning"]==nil){
        [self setShowSecurityWarning:[NSNumber numberWithBool:YES]];
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"showSecurityWarning"];

}
-(void)setShowSecurityWarning:(NSNumber *)showSecurityWarning{
    [[NSUserDefaults standardUserDefaults]setObject:showSecurityWarning forKey:@"showSecurityWarning"];
}



-(NSNumber *)acceptCookies{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"acceptCookies"]==nil){
        [self setAcceptCookies:[NSNumber numberWithBool:YES]];
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"acceptCookies"];
}
-(void)setAcceptCookies:(NSNumber *)acceptCookies{
     [[NSUserDefaults standardUserDefaults]setObject:acceptCookies forKey:@"acceptCookies"];
}



-(NSNumber *)rememberFormData{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"rememberFormData"]==nil){
        [self setRememberFormData:[NSNumber numberWithBool:YES]];
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"rememberFormData"];
}
-(void)setRememberFormData:(NSNumber *)rememberFormData{
    [[NSUserDefaults standardUserDefaults]setObject:rememberFormData forKey:@"rememberFormData"];
}


-(NSNumber *)enableLocation{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"enableLocation"]==nil){
        [self setEnableLocation:[NSNumber numberWithBool:YES]];
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"enableLocation"];
}
-(void)setEnableLocation:(NSNumber *)enableLocation{
    [[NSUserDefaults standardUserDefaults]setObject:enableLocation forKey:@"enableLocation"];

}


-(NSNumber *)rememberPasswords{
    if([[NSUserDefaults standardUserDefaults]objectForKey:@"rememberPasswords"]==nil){
        [self setRememberPasswords:[NSNumber numberWithBool:YES]];
    }
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"rememberPasswords"];
}
-(void)setRememberPasswords:(NSNumber *)rememberPasswords{
    [[NSUserDefaults standardUserDefaults]setObject:rememberPasswords forKey:@"rememberPasswords"];

}


-(void)resetToDefaults{
    NSLog(@"reset to defaults");
    [self setWebDisplayMode:[NSNumber numberWithInt:0]];
    [self setWebFontSize:[NSNumber numberWithInt:2]];
    [self setWebZoomScale:[NSNumber numberWithInt:1]];
    [self setWebUserAgent:[NSNumber numberWithInt:2]];
    [self setTheme:[NSNumber numberWithInt:0]];
    
    
    [self setHowOftenToCheckForUpdate:[NSNumber numberWithInt:0]];
    [self setOrientation:[NSNumber numberWithInt:0]];
    [self setKeepScreenOn:[NSNumber numberWithBool:YES]];
    [self setSuggestion:[NSNumber numberWithBool:YES]];
    [self setLanguage:[NSNumber numberWithInt:0]];
}

@end
